create or replace view vac_app_region_template_4_1 as
with tr as
(
select
  workspace,
  workspace_display_name,
  application_id,
  application_name,
  template_name,
  theme_number,
  theme_class,
  render_form_items_in_table,
  ac_utils.hs(template) template_hs,
  dbms_lob.substr(template,4000, 1)        template_sr1,
  dbms_lob.substr(template,4000, 4000+1 )  template_sr2,
  dbms_lob.substr(template,4000, 8000+1 )  template_sr3,
  dbms_lob.substr(template,4000, 12000+1)  template_sr4,
  ac_utils.hs(template) template2_hs,
  dbms_lob.substr(template2,4000, 1)        template2_sr1,
  dbms_lob.substr(template2,4000, 4000+1 )  template2_sr2,
  dbms_lob.substr(template2,4000, 8000+1 )  template2_sr3,
  dbms_lob.substr(template2,4000, 12000+1)  template2_sr4,
  ac_utils.hs(template) template3_hs,
  dbms_lob.substr(template3,4000, 1)        template3_sr1,
  dbms_lob.substr(template3,4000, 4000+1 )  template3_sr2,
  dbms_lob.substr(template3,4000, 8000+1 )  template3_sr3,
  dbms_lob.substr(template3,4000, 12000+1)  template3_sr4,
  sub_region_header_template,
  sub_region_header_entry_templ,
  sub_region_template,
  plug_table_bgcolor,
  plug_heading_bgcolor,
  plug_font_size,
  is_subscribed,
  subscribed_from,
  last_updated_by,
  last_updated_on,
  translatable,
  component_comment,
  region_template_id
from apex_application_temp_region
)
select
  workspace,
  workspace_display_name,
  application_id,
  application_name,
  template_name,
  theme_number,
  last_updated_by,
  last_updated_on,
  region_template_id,
  u_name,
  u_value,
  to_clob(template_sr1) || to_clob(template_sr2)
  || to_clob(template_sr3) || to_clob(template_sr4)  template_sr,
  to_clob(template2_sr1) || to_clob(template2_sr2)
  || to_clob(template2_sr3) || to_clob(template2_sr4)  template2_sr,
  to_clob(template3_sr1) || to_clob(template3_sr2)
  || to_clob(template3_sr3) || to_clob(template3_sr4)  template3_sr,
  'APEX_APPLICATION_TEMP_REGION' src_view_name
  from
(
select
  workspace,
  workspace_display_name,
  application_id,
  application_name,
  template_name,
  theme_number,
  last_updated_by,
  last_updated_on,
  region_template_id,
  --
  template_sr1,
  template_sr2,
  template_sr3,
  template_sr4,
  --
  template2_sr1,
  template2_sr2,
  template2_sr3,
  template2_sr4,
  --
  template3_sr1,
  template3_sr2,
  template3_sr3,
  template3_sr4,
  u_name,
  u_value
from tr
UNPIVOT INCLUDE NULLS
 ( u_value
   FOR    u_name
   IN
   (
      render_form_items_in_table,
      template_hs,
      template2_hs,
      template3_hs,
      theme_class,
      sub_region_header_template,
      sub_region_header_entry_templ,
      sub_region_template,
      plug_table_bgcolor,
      plug_heading_bgcolor,
      plug_font_size,
      is_subscribed,
      subscribed_from,
      translatable,
      component_comment
   )
 )
) t;

